//
//  YJDCache.m
//  YJDSDK
//
//  Created by tucici on 2017/12/2.
//  Copyright © 2017年 SKL. All rights reserved.
//

#import "YJDCache.h"
#import "NSDictionary+category.h"
#import "NSString+category.h"
@implementation YJDCache
static YJDCache *_cache;
static dispatch_once_t cacheonceToken;
+ (instancetype)cache
{
    if(!_cache)
    {
        dispatch_once(&cacheonceToken, ^{
            _cache = [[YJDCache alloc] init];
        });
    }
    return _cache;
}

+ (NSMutableArray *)yjd_readCache
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    return [defaults mutableArrayValueForKey:SKLTokenKey];
}

+ (BOOL)yjd_cache:(NSMutableArray *)array
{
    if ([array count] > 0)
    {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:[array mutableCopy] forKey:SKLTokenKey];
        return [defaults synchronize];
    }
    else
        return NO;
}

+ (id)yjd_cacheFromKey:(NSString *)key
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:key];
}

+ (void)yjd_cache:(id)object withKey:(NSString *)key
{
    NSUserDefaults *defaults  = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[object mutableCopy] forKey:key];
    [defaults synchronize];
}

+ (void)yjd_deleteWithKey:(NSString *)key
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults removeObjectForKey:key];
    [defaults synchronize];
}

@end
